using System;
using System.Xml;
using DesignByContract;
using Outcoding.GraphGenerator.Entities;
using Outcoding.GraphGenerator.Util.Logging;

namespace Outcoding.GraphGenerator.Composition{
    public class LabelCollectionBuilder : BuilderBase{
        private readonly string mNodeName = XmlTagNames.labelcollection.ToString();

        private XmlNode mNode;

        private string mNodePath{
            get { return "./" + mNodeName; }
        }

        public override void SelectNode(XmlDocument document){
            throw new Exception("The method or operation is not implemented.");
        }

        public override void Compose(){
            throw new Exception("The method or operation is not implemented.");
        }

        public override void Compose(XmlNode node){
            mNode = node.SelectSingleNode(mNodePath);
            try{
                BuildObject(mNode);
            }
            catch (PreconditionException preExc){
                LogManager.Instance.LogWarning("LabelCollection entity could not be created; process aborted.", preExc);
            }
        }

        public override void AppendToParent(object parent){
            Check.Require(parent is CategoryAxis, "Parent object not a valid argument");
            (parent as CategoryAxis).Labels = (LabelCollection) mProduct;
        }

        private void BuildObject(XmlNode axesXmlNode){
            var labelCollection = new LabelCollection();
            mProduct = labelCollection;
        }
    }
}